package cn.bdqn.sys.controller;

import cn.bdqn.model.PageBean;
import cn.bdqn.sys.model.Role;
import cn.bdqn.sys.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author gurilla
 * @create 2019-08-04 10:09
 */
@Controller
@RequestMapping("/sys/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequiresPermissions("sys:role:page")
    @GetMapping
    public String toPage(){
        return "/sys/role";
    }

    @RequiresPermissions("sys:role:list")
    @PostMapping("/list")
    @ResponseBody
    public Object list(PageBean pageBean, String rolename){
        return roleService.list(pageBean, rolename);
    }

    @RequiresPermissions("sys:role:getall")
    @PostMapping("/getall")
    @ResponseBody
    public Object getall(){
        return roleService.getall().getData();
    }

    @RequiresPermissions("sys:role:save")
    @PostMapping("/save")
    @ResponseBody
    public Object save(Role role){
        return roleService.save(role);
    }

    @RequiresPermissions("sys:role:delete")
    @PostMapping("/delete")
    @ResponseBody
    public Object delete(Integer roleid){
        return roleService.delete(roleid);
    }

    @RequiresPermissions("sys:role:setrole")
    @PostMapping("/setroleres")
    @ResponseBody
    public Object setroleres(Integer roleid, String resids){
        return roleService.insertResRole(roleid, resids);
    }
}
